<?php
	
class M_assessment_fees Extends MY_Model{
	
		protected $_table = 'assessment_fees';

		public function __construct()
		{
			parent::__construct();
		}
		
		public function get_all_id()
		{
			$sql = "SELECT enrollment_id 
					FROM assessment_fees 
					WHERE schoolyear_id = ?
					";
			$query = $this->db->query($sql,array($this->c_sy->id));
			return $query->num_rows() >=1 ? $query->result() : FALSE;
		}
		
		public function get_enrollment_id($id)
		{
			$id = intval($id);
			
			$sql = "SELECT e_id
					FROM enrollments 
					WHERE e_student_id = ? 
					LIMIT 1";
			$query = $this->db->query($sql,array($id));
			return $query->num_rows() >=1 ? $query->row() : FALSE;
		}

		public function get_assessment_fee($e_id)
		{
			$e_id = intval($e_id);
			
			$sql = "SELECT remarks,
						   ammt_paid
					FROM assessment_fees 
					WHERE enrollment_id = ? 
					LIMIT 1";
			$query = $this->db->query($sql,array($e_id));
			return $query->num_rows() >=1 ? TRUE : FALSE;
		}
		
		public function print_assessment_fee($e_id)
		{
			$e_id = intval($e_id);
			
			$sql = "SELECT assessment_fees.remarks,
						   assessment_fees.ammt_paid,
						   assessment_fees.or_no,
						   assessment_fees.cheque_no,
						   assessment_fees.payment_mode,
						   assessment_fees.payee,
						   assessment_fees.relation,
						   enrollments.age,
						   enrollments.schedule_for_testing,
						   enrollments.hear_from,
						   employees.last_name,
						   employees.first_name,
						   employees.middle_name,
						   employees.name_ext
					FROM assessment_fees
					LEFT JOIN enrollments ON assessment_fees.enrollment_id = enrollments.e_id	
					LEFT JOIN employees ON assessment_fees.user_trans_id = employees.id
					WHERE assessment_fees.enrollment_id = ?";
			$query = $this->db->query($sql,array($e_id));
			return $query->num_rows() >=1 ? $query->row() : FALSE;
		}
		
		public function assessment_fee($data)
		{
			$this->db->insert('assessment_fees', $data); 
			return $this->db->affected_rows() >=1 ? TRUE : FALSE;
		}

	public function get_reserved()
	{
		$sql = "SELECT spr_enrollment_id,
					   spr_id
				FROM student_payment_records 
				WHERE spr_schoolyear_id = ?	
				AND spr_for_the_month_of = ? ";
		$query = $this->db->query($sql,array($this->c_sy->id,'Reservation'));
		return $query->num_rows() >=1 ? $query->result() : FALSE;
	}
}